import React from 'react';
import { useRoute, useNavigation } from '@react-navigation/native';
import { FuelFormPage } from './FuelFormPage';
import { RepairFormPage } from './RepairFormPage';
import { MaintenanceFormPage } from './MaintenanceFormPage';
import { CarWashFormPage } from './CarWashFormPage';
import {
  FuelFormData,
  RepairFormData,
  MaintenanceFormData,
  CarWashFormData,
} from './types';
import { Nav } from '@/modules';

interface RouteParams {
  type: 'fuel' | 'repair' | 'maintenance' | 'car_wash';
  initialData?: any;
}

export const FormPage: React.FC = () => {
  const route = useRoute();
  const { type, initialData } = route.params as RouteParams;
  console.log('FormPage', type);
  const handleSubmit = (data: any) => {
    console.log('表单提交数据:', data);
    // 这里可以处理表单数据，比如保存到store或发送到API
    Nav.goBack();
  };

  const handleCancel = () => {
    Nav.goBack();
  };

  // 根据type参数渲染不同的表单
  switch (type) {
    case 'fuel':
      return (
        <FuelFormPage
          initialData={initialData}
          onSubmit={handleSubmit}
          onCancel={handleCancel}
        />
      );

    case 'repair':
      return (
        <RepairFormPage
          initialData={initialData}
          onSubmit={handleSubmit}
          onCancel={handleCancel}
        />
      );

    case 'maintenance':
      return (
        <MaintenanceFormPage
          initialData={initialData}
          onSubmit={handleSubmit}
          onCancel={handleCancel}
        />
      );

    case 'car_wash':
      return (
        <CarWashFormPage
          initialData={initialData}
          onSubmit={handleSubmit}
          onCancel={handleCancel}
        />
      );

    default:
      return (
        <FuelFormPage
          initialData={initialData}
          onSubmit={handleSubmit}
          onCancel={handleCancel}
        />
      );
  }
};
